import java.util.Scanner;
import java.util.Stack;

class Parenthesis {
    public boolean chkParenthesis(String A, int n) {
        Stack<Character> stack = new Stack<>();
        for(int i = 0; i<n; i++) {
            char ch = A.charAt(i);
            if(ch == '(') {
                stack.push(ch);
            }else if(ch == ')') {
                stack.pop();
            }else {
                return false;
            }
        }
        return stack.isEmpty();
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int a = 0, b = 1, c = 0;
        while(c<n) {
            c = a+b;
            a = b;
            b = c;
            //System.out.print(c + " ");
        }
        int res = Math.min(c-n, n-a);
        System.out.println(res);
    }
}
